package com.shiguiwu.springmybatis.spring.event.spring;

import lombok.Getter;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 * @description: 用户注册服务
 * @author: stone
 * @date: Created by 2021/4/24 22:35
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.event.spring
 */
@Component
public class UserRegisterService implements ApplicationEventPublisherAware {

    @Getter
    private ApplicationEventPublisher applicationEventPublisher;

    public void register(String username) {
        //用户注册(将用户信息入库等操作)
        System.out.println(String.format("用户【%s】注册成功", username));
        //发布注册成功事件
        this.applicationEventPublisher.publishEvent(new UserRegEvent(this, username));

//        this.applicationEventPublisher.publishEvent(new UserRegEvent(this, username));
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }
}
